package cc.eddic.pratice.programmingparadigms.exam.impl;

import cc.eddic.pratice.programmingparadigms.exam.Gender;
import cc.eddic.pratice.programmingparadigms.exam.MasterDataService;
import cc.eddic.pratice.programmingparadigms.exam.domain.Category;
import cc.eddic.pratice.programmingparadigms.exam.domain.Exam;
import cc.eddic.pratice.programmingparadigms.exam.domain.Student;
import cc.eddic.pratice.programmingparadigms.exam.domain.SubCategory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

public class MasterDataServiceScwImpl implements MasterDataService {
    @Override
    public List<Category> getCategories() {
        Category software = new Category("软件开发基础");
        software.add(new SubCategory("基础"));
        software.add(new SubCategory("HTML"));
        software.add(new SubCategory("SQL"));
        software.add(new SubCategory("DOS"));
        software.add(new SubCategory("Linux"));
        software.add(new SubCategory("数学"));

        Category office = new Category("办公软件");
        office.add(new SubCategory("Word"));
        office.add(new SubCategory("Excel"));

        Category coding = new Category("代码");
        coding.add(new SubCategory("代码"));

        return new ArrayList<Category>(Arrays.asList(software, office, coding));
    }


    @Override
    public List<Student> getStudents() {
        return new ArrayList<>(Arrays.asList(
                new Student("李惠", Gender.FEMALE, "软件工程"),
                new Student("谭雨晴", Gender.FEMALE, "通信工程"),
                new Student("李馨", Gender.FEMALE, "软件工程"),
                new Student("曾奕哲", Gender.MALE, "软件工程"),
                new Student("车晓满", Gender.MALE, "软件工程"),
                new Student("王巧家", Gender.MALE, "交通工程"),
                new Student("孙晨玮", Gender.MALE, "土木工程"),
                new Student("崔相元", Gender.MALE, "数据科学"),
                new Student("韩睿洁", Gender.FEMALE, "软件工程")
        ));
    }

    @Override
    public List<Exam> getExams() {

//        List<Exam> examList = new ArrayList<>();
//
//        Optional<Exam> optionalExam = find(examList, new Predicate<Exam>() {
//            @Override
//            public boolean test(Exam exam) {
//                return false;
//            }
//        });
//        if (optionalExam.isPresent()) {
//            Exam exam = optionalExam.get();
//        }
//
//        Exam exam = find(examList, new Predicate<Exam>() {
//            @Override
//            public boolean test(Exam exam) {
//                return false;
//            }
//        }).orElseThrow(() -> new IllegalArgumentException(""));
//
//        Exam examMaybeDefault = find(examList, new Predicate<Exam>() {
//            @Override
//            public boolean test(Exam exam) {
//                return false;
//            }
//
//        }).orElseGet(() -> new Exam("Default exam"));

        return new ArrayList<>(Arrays.asList(
                new Exam("7-31 写代码"),
                new Exam("8-15 理论"),
                new Exam("8-25 答辩")));


    }

    @Override
    public <T> Optional<T> find(List<T> genericList, Predicate<T> predicate) {
        for (T o : genericList) {
            if (predicate.test(o))
                return Optional.of(o);
        }
        return Optional.empty();
    }
}
